package com.xbongbong.saas.domain.dao;

import com.xbongbong.paas.domain.entity.StageLogEntity;
import com.xbongbong.saas.domain.entity.ClueStageLogEntity;
import com.xbongbong.saas.domain.entity.ext.StageLogEntityExt;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

public interface ClueStageLogDao {

    Integer insert(ClueStageLogEntity clueStageLog);
    Integer update(ClueStageLogEntity clueStageLog);

    void insertBatch(List<ClueStageLogEntity> clueStageLogList);
    Integer deleteByStageProcessIdAndDataIdIn(@Param("list") List<Long> dataIdIn, @Param("corpid") String corpid, @Param("formId") Long formId, @Param("stageProcessId") Long stageProcessId, @Param("stageId") Long stageId);
    Integer deleteByKey(@Param("key") Long key, @Param("corpid") String corpid);
    ClueStageLogEntity getByKey (@Param("key") Long key, @Param("corpid") String corpid);

    List<ClueStageLogEntity> findEntitys(@Param("param") Map<String, Object> param);
    Integer getEntitysCount(@Param("param") Map<String, Object> param);

    List<StageLogEntityExt> getAverageStayTime(@Param("param")Map<String ,Object> param);

    void updateBatch(@Param("list") List<ClueStageLogEntity> clueStageLogList,@Param("corpid") String corpid);

    void updateBatch4Script(@Param("list") List<ClueStageLogEntity> clueStageLogList);

    List<ClueStageLogEntity> findStageLogWithoutStage();

    Integer deleteBatch(@Param("list") List<StageLogEntity> stageLogEntityList, @Param("corpid") String corpid);

    /**
     * 根据dataId 查找当前数据所处阶段
     * @param corpid
     * @param formId
     * @param dataId
     * @return
     */
    ClueStageLogEntity getIsNowStage(@Param("corpid") String corpid, @Param("formId") Long formId, @Param("dataId") Long dataId);

    Long getAvgStayTime(@Param("corpid") String corpid, @Param("stageProcessId") Long stageProcessId, @Param("stageId") Long stageId);

    List<Long> findUsedStageProcessId(@Param("corpid") String corpid, @Param("formId") Long formId, @Param("stageProcessIdIn") List<Long> stageProcessIdIn);
}
